package _03;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author ：Rwto
 * @date ：Created in 2021/7/9 11:19
 * @description：找出重复的数字   优化空间，O（1）
 */
public class Solution {
    public int findRepeatNumber(int[] nums) {
        for(int i = 0; i<nums.length;i++){
            int t = nums[i];
            if(t<0) t+=nums.length;
            if(nums[t]>=0)
                nums[t]-=nums.length;
            else
                return t;
        }
        return -1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<>();
        while(sc.hasNext()){
            list.add(sc.nextInt());
        }
        int[] nums = new int[list.size()];
        for(int i = 0; i<list.size();i++){
            nums[i] = list.get(i);
        }
        System.out.println(new Solution().findRepeatNumber(nums));
    }
}
